﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.IO;

namespace TestDxfDocument
{
    class Draw
    {
        
        public static void DrawOneRect(Dictionary<string, Object> data, int width=200, int height=100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(1) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y +3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);

            {
                Vector2 pR1 = new Vector2(3, Math.Sin(lt.Y - lb.Y));
                Vector2 pR2 = new Vector2(0, Math.Sin(lt.Y - lb.Y));
                Vector2[] lLineR1 = { pR1, pR2 };
                fun.drawBLine(dxf, lLineR1, 0.05, skdimensioning);

            }
            {
                Vector2 pR1 = new Vector2(3, Math.Sin(lt.Y - lb.Y));
                Vector2 pR2 = new Vector2(5, 0);
                Vector2[] lLineR1 = { pR1, pR2 };
                fun.drawBLine(dxf, lLineR1, 0.05, skdimensioning);

            }
            {
                Vector2 pR1 = new Vector2(Math.Abs(lt.X - rt.X), 2);
                Vector2 pR2 = new Vector2(6, 0);
                Vector2[] lLineR1 = { pR1, pR2 };
                fun.drawBLine(dxf, lLineR1, 0.05, skdimensioning);
            }
            {
                Vector2 temp1 = new Vector2(0, 7);
                Vector2 temp2 = new Vector2(5, 0);
                Vector2[] line1 = { temp1, temp2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            {
                Vector2 temp3 = new Vector2(7, Math.Sin(lt.Y - lb.Y));
                Vector2 temp4 = new Vector2(5, 0);
                Vector2[] line2 = { temp3, temp4 };
                fun.drawBLine(dxf, line2, 0.05, skdimensioning);
            }
            {
                Vector2 temp1 = new Vector2(3, Math.Sin(rt.Y - rb.Y));
                Vector2 temp2 = new Vector2(Math.Sin(lt.X - rb.X));
                Vector2[] line1 = { temp1, temp2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }
        public static void DrawTwoRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(2) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 pR1 = new Vector2(3, Math.Sin(lt.Y - lb.Y));
                Vector2 pR2 = new Vector2(5, 0);
                Vector2[] lLineR1 = { pR1, pR2 };
                fun.drawBLine(dxf, lLineR1, 0.05, skdimensioning);
            }
            {

                Vector2 pR1 = new Vector2(Math.Sin(lt.X - rt.X), 6);
                Vector2 pR2 = new Vector2(6, 0);
                Vector2[] lLineR1 = { pR1, pR2 };
                fun.drawBLine(dxf, lLineR1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);

            

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void DrawTriRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(3) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.10, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.10, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.10, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.10, skdimensioning);
            {
                Vector2 vec1 = new Vector2(Math.Sin(lt.X - rt.X), 3);
                Vector2 vec2 = new Vector2(0, 5);
            }
            string path = Convert.ToString(data["path"]);

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void DrawFourRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(4) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 vec1 = new Vector2(Math.Sin(lt.X - rt.X), 6);
                Vector2 vec2 = new Vector2(0, 4);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void DrawFiveRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(5) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 vec1 = new Vector2(3, 5);
                Vector2 vec2 = new Vector2(6, 0);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void DrawSixRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(6) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 vec1 = new Vector2(Math.Sin(lt.X - rt.X), 6);
                Vector2 vec2 = new Vector2(0, 5);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            {
                Vector2 vec1 = new Vector2(3, 6);
                Vector2 vec2 = new Vector2(5, 0);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void DrawSevenRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(7) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);


            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        //
        public static void DrawEightRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(9) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);
            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 vec1 = new Vector2(Math.Sin(lt.X - rt.X), 3);
                Vector2 vec2 = new Vector2(0, 7);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawPlinetype(dxf, line1, 0.1, skdimensioning, Linetype.Dashed);
            }
            {
                Vector2 vec1 = new Vector2(Math.Sin(lt.X - 6), 7);
                Vector2 vec2 = new Vector2(0, 2);
                Vector2 vec3 = new Vector2(Math.Atan(lt.X - 6), 5 - lt.Y);
                Vector2 vec4 = new Vector2();
                Vector2[] line1 = { vec1, vec2 };
                fun.drawPlinetype(dxf, line1, 0.1, skdimensioning, Linetype.Dashed);
            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        //
        public static void DrawNineRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(30) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 temp1 = new Vector2(0, 6);
                Vector2 temp2 = new Vector2(5, 0);
                Vector2[] line1 = { temp1, temp2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            {
                Vector2 temp3 = new Vector2(5, Math.Sin(lt.Y - lb.Y));
                Vector2 temp4 = new Vector2(6, 0);
                Vector2[] line2 = { temp3, temp4 };
                fun.drawBLine(dxf, line2, 0.05, skdimensioning);
            }
            {
                Vector2 temp1 = new Vector2(6, Math.Sin(rt.Y - rb.Y));
                Vector2 temp2 = new Vector2(Math.Sin(lt.X - rb.X), 6);
                Vector2[] line1 = { temp1, temp2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);
            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        //
        public static void DrawTenRect(Dictionary<string, Object> data, int width = 200, int height = 100, int g_Mi = 10)
        {
            DxfDocument dxf = new DxfDocument();
            Layer skdimensioning = new Layer("rect1") { Color = AciColor.FromCadIndex(96) };
            Vector2 lt = new Vector2(0, 0);
            Vector2 lb = new Vector2(0, lt.Y + 3);
            Vector2 rt = new Vector2(lt.X + 5, 0);
            Vector2 rb = new Vector2(lt.X + 3, lt.Y + 5);

            Vector2[] LineTop = { lt, rt };
            fun.drawBLine(dxf, LineTop, 0.05, skdimensioning);
            Vector2[] LineLeft = { lt, lb };
            fun.drawBLine(dxf, LineLeft, 0.05, skdimensioning);
            Vector2[] LineRight = { rt, rb };
            fun.drawBLine(dxf, LineRight, 0.05, skdimensioning);
            Vector2[] LineBottom = { lb, rb };
            fun.drawBLine(dxf, LineBottom, 0.05, skdimensioning);
            {
                Vector2 vec1 = new Vector2(0, 7);
                Vector2 vec2 = new Vector2(Math.Sin(lt.X - rt.X), 6);
                Vector2[] line1 = { vec1, vec2 };
                fun.drawBLine(dxf, line1, 0.05, skdimensioning);

            }
            string path = Convert.ToString(data["path"]);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }
    }
}
